/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-06 10:52:54
 * @LastEditTime: 2022-06-28 20:34:24
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service/admin"
)

/**
 * @description: 方法描述：返回灌水
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetIrrigation(c *gin.Context) {
	var param_ common.Detail
	if err := c.BindQuery(&param_); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}
	ii := admin.AdminIrrigService.GetIrrigation(param_.Id)

	common.ResponseDetailToJson(http.StatusOK, ii, "success!", c)
}

/**
 * @description: 方法描述：注水
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func SetIrrigation(c *gin.Context) {
	var param common.Irrigation

	if err := c.ShouldBind(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}
	err := admin.AdminIrrigService.SetIrrigation(param)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "注水成功", c)
}

/**
 * @description: 方法描述：获取灌水列表
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetIrrigationList(c *gin.Context) {
	var param common.AdminGoodsList

	if err := c.BindQuery(&param); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	il := admin.AdminIrrigService.GetIrrigationList(param)

	common.ResponseListToJson(http.StatusOK, int(il.Page), int(il.PerPage), int(il.Total), il, c)
}
